package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;


    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") StrategyCatalogQueryObject qo) {
        PageInfo pageInfo = strategyCatalogService.getList(qo);
        List<Strategy> Strategys = strategyService.selectAll();
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("Strategys",Strategys);
        return "strategyCatalog/list";
    }
    @RequestMapping("/getStrategyCatalogByStrategyId")
    @ResponseBody
    public Object getStrategyCatalogByStrategyId(Long strategyId) {
        List<StrategyCatalog> strategyCatalogs=   strategyCatalogService.getStrategyCatalogByStrategyId(strategyId);
        return strategyCatalogs;
    }




    @RequestMapping("/save")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog strategyCatalog) {
        JSONResult json = new JSONResult();
        try {

        strategyCatalogService.saveOrUpdate(strategyCatalog);
        }catch (Exception e){
            e.printStackTrace();
            json.mark(e.getMessage());
        }

        return json;
    }

}
